import 'package:flutter/material.dart';
import 'package:flutter_rider/utils/log.dart';
import 'package:flutter_rider/utils/screen_fit.dart';
import '../../../main/widgets/ui_constant.dart';
import '../ext/u_text.dart';

class RadioLayout extends StatefulWidget {
  Function(int) onChanged;
  int index = -1;
  double spacing = 0;
  double runSpacing = 0;
  List<String> values;

  RadioLayout(
      {Key? key,
      this.index = -1,
      required this.values,
      this.spacing = 0,
      this.runSpacing = 0,
      required this.onChanged})
      : super(key: key);

  @override
  State createState() => _RadioLayoutState();
}

class _RadioLayoutState extends State<RadioLayout> {
  @override
  Widget build(BuildContext context) {
    return Wrap(
      spacing: widget.spacing,
      runSpacing: widget.runSpacing,
      children: widget.values.asMap().keys.map((e) => _renderSortItem(e)).toList(),
    );
  }

  Widget _renderSortItem(index) {
    Log.i("....");
    var isSelect = widget.index == index;
    return GestureDetector(
        onTap: () {
          widget.onChanged(index);
        },
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            Icon(
              isSelect ? Icons.radio_button_on : Icons.radio_button_off,
              size: 20.rpx,
              color: isSelect ? UIColor.color_primary : UIColor.color_t1,
            ),
            SizedBox(width: 3.rpx),
            UText.getMainText(widget.values[index]),
          ],
        ));
  }
}
